package com.cqc.pgy01;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.pgyersdk.activity.FeedbackActivity;
import com.pgyersdk.feedback.PgyFeedback;
import com.pgyersdk.feedback.PgyFeedbackShakeManager;
import com.pgyersdk.update.PgyUpdateManager;
import com.pgyersdk.update.UpdateManagerListener;

/**
 * mapping在： \PGY01\app\build\outputs\mapping\release
 */
public class MainActivity extends BaseActivity implements View.OnClickListener {

    private static final String TAG = "MainActivity";
    private Button btn1;
    private Button btn2;
    private Button btn3;
    private Button btn4;
    private Button btn5;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //        initFAB2();
        initFAB();
//        initToolbar("哈哈哈");

        findViews();
        initViews();
    }

    private void initViews() {
        btn1.setOnClickListener(this);
        btn2.setOnClickListener(this);
        btn3.setOnClickListener(this);
        btn4.setOnClickListener(this);
        btn5.setOnClickListener(this);


    }

    private void findViews() {
        btn1 = (Button) findViewById(R.id.btn1);
        btn2 = (Button) findViewById(R.id.btn2);
        btn3 = (Button) findViewById(R.id.btn3);
        btn4 = (Button) findViewById(R.id.btn4);
        btn5 = (Button) findViewById(R.id.btn5);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn1:
                //默认的更新
                PgyUpdateManager.register(this);
                //                //需要自己自己实现跟新dialog+下载+安装
                //                PgyUpdateManager.register(MainActivity.this, new UpdateManagerListener() {
                //                    @Override
                //                    public void onNoUpdateAvailable() {
                //                        Log.d(TAG, "当前是最新版本");
                //                    }
                //
                //                    @Override
                //                    public void onUpdateAvailable(String s) {
                //                        Log.d(TAG, "可以更新");
                //                    }
                //                });
                break;
            case R.id.btn2:
                testCrashReport();
                break;
            case R.id.btn3:
                //                PgyFeedbackShakeManager.register(MainActivity.this, true);
                PgyFeedback.getInstance().showDialog(MainActivity.this);
                break;
            case R.id.btn4:
                // 以Activity的形式打开，这种情况下必须在AndroidManifest.xml配置FeedbackActivity
                // 打开沉浸式,默认为false
                FeedbackActivity.setBarImmersive(true);
                PgyFeedback.getInstance().showActivity(MainActivity.this);
                break;
            case R.id.btn5:
                PgyFeedbackShakeManager.unregister();
                break;
        }
    }


    private void testCrashReport() {
        throw new RuntimeException("这是个测试bug!");
    }


    public void initFAB() {
        FloatingActionButton fab = new FloatingActionButton(this);
        fab.setActivated(true);
        fab.setRight(20);
        fab.setBottom(20);
        fab.setImageResource(android.R.drawable.ic_input_add);
        fab.show();
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "fab onClick");
            }
        });

    }
}
